<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>意见反馈</title>
    <link rel="stylesheet" href="mobile/layui/css/layui.mobile.css">
    <link rel="stylesheet" href="mobile/layui/css/layui.css">
    <link rel="stylesheet" href="mobile/css/yj_css.css">
    <link rel="stylesheet" href="mobile/layer/mobile/need/layer.css">
    <link rel="stylesheet" href="mobile/css/swiper.min.css">
</head>
<body>
<header class="yj-header">
    <a href="javascript:history.go(-1)" class="yj-header-return layui-icon">&#xe603;</a>
    <span>租客评分</span>
    <a class="yj-header-meau"></a>
</header>
<div class="yj-content">
    <div class="yj-goods-parameter yj-pad-lr yj-bgfff yj-border-t" id="commentsAndReplies">
        <button onclick="addComment()">添加评分</button>

    </div>

    <!--弹出框-->
    <div id="addCommentDiv" title="添加评分" style="display: none;padding: 40px 40px;">
        <form action="tenantComment/addComment" id="addForm" enctype="multipart/form-data" method="post">
            <table>
                <tr>
                    <td>评分:</td>
                    <td id="starScore"></td>
                </tr>
                <tr>
                    <td><input type="hidden" id="oId" name="oId"></td>
                    <td><input type="hidden" id="getScore" name="tcScore"></td>
                </tr>
            </table>
        </form>
    </div>
</div>
<script src="mobile/js/swiper.min.js"></script>
<script th:src="@{/mobile/layui/layui.js}"></script>
<script src="mobile/js/jquery.min.js"></script>
<script src="mobile/js/yj_js.js"></script>
<script src="mobile/js/jQuery.form.js"></script>
<script th:inline="javascript">
    var url = [[@{/}]];
        layui.use("layer", function () {
            var layer = layui.layer;
        });
        function getQueryVariable(variable)
        {
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i=0;i<vars.length;i++) {
                var pair = vars[i].split("=");
                if(pair[0] == variable){return pair[1];}
            }
            return(false);
        }
</script>
<script type="text/javascript">
    $(document).ready(function () {
        var oId = getQueryVariable("id");
        $.ajax({
            url:url+"/tenantComment/allComment?oId="+oId,
            success:function (result) {
                //评论
                var comments=result.result;
                for (var i=0;i<comments.length;i++){
                    var comment=comments[i];
                    var tab=$("<div></div>");
                    var tr1=$("<div></div>");
                    //var tr2=$("<div></div>");
                    //var tr3=$("<div></div>");
                    var tr4 = $("<div></div>");
                    //var tr5=$("<div></div>");
                    var tr9=$("<div></div>");
                    var tr10=$("<div></div>");
                    var uName=$("<span></span>").text(comment.ccomment.uName);
                    //var cpcTime=$("<span></span>").text(comment.cpcTime);
                    //var cpcContent=$("<span></span>").text(comment.cpcContent);
                    var operation=$("<span></span>");
                    //var cpcPic=$("<span></span>");
                    //var addReply=$("<button onclick='addReply("+comment.cpcId+','+comment.uId+")'>回复</button>");
                    //var deleteComment=$("<button onclick='deleteComment("+comment.tcId+")'>撤回</button>");
                    //var pic=$("<image src='upload/"+comment.cpcPic+"' style='height: 160px;width: 150px'>");
                    var cutOff=$("<span></span>").text("---------------------------------------");
                    var cutOffTop=$("<span></span>").text("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
                    var starNum=$("<button onclick='addStar("+comment.tcScore+")'>查看评分</button>");
                    //addStar(comment.uId);
                    //operation.append(addReply);
                    //operation.append(deleteComment);
                    //cpcPic.append(pic);
                    tr1.append(uName);
                    //tr2.append(cpcTime);
                    //tr3.append(cpcContent);
                    //tr3.append(operation);
                    //tr5.append(cpcPic);
                    tr4.append(starNum);
                    tr9.append(cutOff);
                    tr10.append(cutOffTop);
                    tab.append(tr10);
                    tab.append(tr1);
                    //tab.append(tr2);
                    //tab.append(tr3);
                    //tab.append(tr5);
                    tab.append(tr4);
                    tab.append(tr9);
                    $("#commentsAndReplies").append(tab);

                }
            }
        })
    })

    //评分星星
    function addStar(tcScore) {
        layui.use('rate', function () {
            var rate = layui.rate;

            //渲染
            var ins1 = rate.render({
                elem: '#addStars'  //绑定元素
                , length: 5
                , value: tcScore
                , readonly: true
            });
        });
        layer.open({
            type: 1,
            area: ['250px', '150px'],
            shadeClose: true, //点击遮罩关闭
            content: $('#addStars'),
            end: function () {
                $("#addStars").hide();
            }
        });

    }
    //添加评论
    function addComment() {
        var id = getQueryVariable("id");
        $("#oId").val(id);
        var index =layer.open({
            title: ['添加评论', 'font-size:18px;text-align:center;'],
            type: 1,
            area: ['400px', '270px'], //宽高
            //弹出对应id的html页面addScheduleDiv
            content: $('#addCommentDiv'),
            shade:0,
            zIndex:3,
            btn: ["确认", "取消"],
            //点击确认执行的方法
            yes: function (index, layero) {
                //要提交的ajax
                var option = {
                    url : url+'/tenantComment/addComment',
                    type : 'POST',
                    dataType : 'json',
                    success : function(data) {
                        var msg="";
                        if (data.msg == "添加成功") {
                            msg="评分成功！";

                        }else{
                            msg="评分失败！";
                        }
                        layer.msg(msg);
                        //清空输入框
                        $("#oId").val("");
                        $("#tcScore").val("");
                        //关闭弹出层
                        layer.close(index);
                    }
                };
                //提交
                $("#addForm").ajaxSubmit(option);

                setTimeout(function(){
                    window.location.reload();
                },1000);
            }
        });
        layui.use('rate', function () {
            var rate = layui.rate;

            //渲染
            var ins1 = rate.render({
                elem: '#starScore'  //绑定元素
                , length: 5
                , value: 0
                , readonly: false
                , choose: function(value){
                    $("#getScore").val(value);
                }
            });
        });
    }
</script>
<div id="addStars" title="评分" style="display: none;padding: 40px 40px;"></div>
</body>
</html>